<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件获取父组件的数据</title>
    <script src="../lib/vue.js"></script>
</head>
<body>

<div id="box">
    <aaa></aaa>
</div>
    <template id="temp-a">
        <div>
            <h3>父组件->{{msg}}</h3>
            <bbb @send-msg="get"></bbb>
        </div>
    </template>

    <template id="temp-b">
        <div>
            <p>子组件</p>
            <button @click="send">发送</button>
        </div>
    </template>



<script>

    var vm = new Vue({
        el: '#box',
        components: {
            'aaa': {
                template: '#temp-a',
                data: function () {
                    return {
                        msg: "我是父组件的数据"
                    }
                },
                methods:{
                    get: function (msg) {
                        this.msg = msg;
                    }
                },
                components: {
                    'bbb': {
                        template: '#temp-b',
                        data: function () {
                          return {
                              bmsg: "数据来自子组件"
                          }
                        },
                        methods:{
                            send: function () {
                                this.$emit('send-msg',this.bmsg)
                            }
                        }
                    }
                }
            }
        }

    })
</script>
</body>
</html>